package org.example.web.controllers;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.java.Log;
import org.example.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;

@RestController
@Log    //lombok日志注解
@Tag(name = "show hello", description = "显示不同语言的hello")
public class HelloController {

    @Autowired
    private Random r;

    @Operation(summary = "显示hello", description = "显示不同语言的hello")
    @GetMapping("/hello")
    public ResponseResult hello() {
        log.info("有请求来了，访问hello方法");
        String str = "hello";
        int n = r.nextInt(3);
        if (n == 1) {
            str = "你好";
        } else if (n == 2) {
            str = "안녕하세요";
        }
        return ResponseResult.builder().code(1).data(str).build();
    }
}